home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17261 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c,comp.lang.c++
  4. Subject: Re: sizeof() question >>> :)
  5. Date: 14 Apr 1996 14:45:27 -0700
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4krrlnINN7o5@keats.ugrad.cs.ubc.ca>
  8. References: <1996Apr12.061927@topaz> <31714828.1574068@news.linex.com>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <31714828.1574068@news.linex.com>,
  12. Marty Fried <mfried@linex.com> wrote:
  13.  >Once upon a time (OK, it was 12 Apr 96 06:19:27 +1000),
  14.  >naderr@topaz.cqu.edu.au wrote:
  15.  >
  16.  >>Hi,
  17.  >>
  18.  >>How can I get, with a pointer,  the sizeof  of an  array that is
  19.  >>pointed by the pointer ?  (No it's not a tounge twister :)
  20.  >>
  21.  >>  while (!done) {
  22.  >>    ch = getchar();
  23.  >>    if (cp - *ct < sizeof(XXXXXXX)-1) {
  24.  >>      *cp++ = ch;
  25.  >>    } else {
  26.  >>      beep();
  27.  >>    }  
  28.  >>  }
  29.  >
  30.  >You can't do it.  The only thing you could do is to use exception
  31.  >handling, and copy the characters within a try block until you get
  32.  >an exception.  I'm not sure if even that will give you the exact size
  33.  >or work all the time, although it will prevent an exception from
  34.  >causing the program to crash.
  35.  
  36. Oh god. I've heard enough overly complex answers to this simple problem from
  37. comp.lang.c++ to convince me that it might as well be re-written into
  38. interpreted Lisp, and executed on Vax emulator...
  39.  
  40. Let's no lose sight of the fact that all the chap wants to do is read some text
  41. fields into character arrays: something that has been frequently done since the
  42. days of punched cards and hardcopy terminals.
  43.